<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * Adminlog Controller
 * Build by Phuc Nguyen
 * Contact : nguyenvanphuc0626@gmail.com
 */

class Advance_model extends MY_Model{
	
	public function __construct(){
		parent::__construct();
		$this->table_name = 'book_history';
	}

        public function init_data($right){
		return array(
                                array(
						'name' => 'customerID',
						'label' => $this->lang->line('customerID'),
						'width' => '2%',
						'sort'  => FALSE,
						'searchoptions' => false
				),
                                array(
						'name' => 'ship_name_customer',
						'label' => $this->lang->line('ship_name_customer'),
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				),
				array(
						'name' => 'booking',
						'label' => $this->lang->line('booking'),
						'width' => '20%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'net_fare',
						'label' => $this->lang->line('net_fare'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'sale_fare',
						'label' => $this->lang->line('sale_fare'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'real_fare',
						'label' => $this->lang->line('real_fare'),
						'width' => '5%',
						'sort'  => FALSE,
						'searchoptions' => false
				),array(
						'name' => 'payment_air',
						'label' => $this->lang->line('payment_air'),
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				),
                                array(
						'name' 	=> 'lastupdated',
						'label' => $this->lang->line('lastupdated'),
						'width' => '10%',
						'sort'  => FALSE,
						'searchoptions' => false
				)
		);
	}
	
	public function json_data($controller, $right){
		$this->datatables
		->select("tbl.customerID,tbl.booking_customer_name,tbl.booking,tbl.net_fare,tbl.sale_fare, tbl.real_fare, tbl.payment_air,tbl.lastupdated")
		->from($this->table_name.' AS tbl')
                ->where('advance','1');
	
		$this->datatables->set_produce_output(false);
		$ouput = $datatables = $this->datatables->generate();
		unset($ouput['aaData']);
		$ouput['aaData'] = array();             

		foreach($datatables['aaData'] as $item){
			$ouput['aaData'][] = array(
					$item['customerID'],
                            		str_replace('||', '<br/>', $item['booking_customer_name']),
                                        implode("<br/>",json_decode($item['booking'])),
                                        $this->bookinglib->my_number_format($item['net_fare'],2, ',', ','),
                                        $this->bookinglib->my_number_format($item['sale_fare'],2, ',', ','),
                                        $this->bookinglib->my_number_format($item['real_fare'],2, ',', ','),
                                        ($item['payment_air'] == 1)?'Đã Thanh Toán':'Chưa thanh toán',
                                        date("d-m-Y H:i:s",$item['lastupdated']),
					$this->add_button_payment($controller, $right, $item['customerID'])
			);
		}
	
		return json_encode($ouput);
	}

}